package com.icangya.common.config;

import com.icangya.Value.FootBall;
import com.icangya.domain.AdvertRecord;
import com.icangya.service.IAdvertService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Random;

public class PageViewsThread  extends Thread  {


    @Autowired
    private IAdvertService iAdvertService;

    private final org.slf4j.Logger logger = LoggerFactory.getLogger(this.getClass());

    public volatile boolean flag = true;

    public void run() {
        while (flag){
            //等于 0 就是关闭浏览量虚假自动增加
//                   logger.info("*************"+FootBall.ADVERT_SHAMPAGEVIEW+"***********");
            if (FootBall.ADVERT_SHAMPAGEVIEW == 1){
                try {
//                            logger.info("*************获取指定广告***********");
                    List<AdvertRecord> advertRecordList =  iAdvertService.getAdvertRecordShame();
//                            logger.info("*************获取指定广告数量"+advertRecordList.size()+"***********");
                    // 每隔3秒 将指定广告数组的get(i)增加浏览量
                    for (int i =0;i<advertRecordList.size();i++){
                        Thread.sleep(1000);
                        int ramd = new Random().nextInt(20) +1;
//                                logger.info("此次浏览量虚假添加的随机整数为："+ramd + "广告ID：" + advertRecordList.get(i).getId());
                        iAdvertService.updateAdvertShampageview(advertRecordList.get(i).getId(),advertRecordList.get(i).getShamPageView()+ramd);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }


}
